* Nicolai Petrovsky
* nicolai.petrovsky@uky.edu


* This do-file generates all variables and obtains all results reported 
* in the Journal of Politics (2009) article 
* "Democracy and Government Performance: Holding Incumbents Accountable 
*  in English Local Governments"
* by George A. Boyne, Oliver James, Peter John, and Nicolai Petrovsky


* Stata version 9.2
* last modified September 7, 2012


* The first step you have to take is to download our data set from the 
* UK Data Archive.  Please go to 
* http://store.data-archive.ac.uk/store/
* and on the right-hand side, under "SEARCH PROJECTS", 
* search for "Petrovsky".  
* You will be taken to our data set.  

* Please download it (the filename is BoyneJamesJohnPetrovsky.dta) and 
* save it in the same directory as this do-file.  

* Then , please use Stata's command
* cd
* to change to that directory.

* Now you can run this do-file.


* How to find the result(s) you are interested in: 

* Since there is a lot of material in this do-file, you can find the results 
* for the items that most interest you in the following way: 
* After running this do-file, view the log-file (JOP2009.smcl) and search within it for 
* "Page 1281" if you'd like to see a result from page 1281 in the article; same 
* for all other pages with results.  
* (For searchin within the log-file, click the search button on the top left-hand 
*  side of the Stata viewer.)

clear
version 9.2
set more off
set memory 40m
set scheme s1mono

* Open a log and allow for replacement
log using JOP2009.smcl, replace

* Open data
use BoyneJamesJohnPetrovsky.dta
save workfile, replace

* Generate necessary variables

#delimit ;

/* Generate support for incumbent variable */
/* (This variable is called "support4incumbent".) */
gen lagcontrol = L1.polcontrol;
gen support4incumbent = .;
replace support4incumbent = convote if (elec == 1 | elec == 2) & lagcontrol == 1;
replace support4incumbent = labvote if (elec == 1 | elec == 2) & lagcontrol == 2;
replace support4incumbent = ldvote if (elec == 1 | elec == 2) & lagcontrol == 3;
gen lagcoal_con_involved = L1.coal_con_involved;
gen lagcoal_lab_involved = L1.coal_lab_involved;
gen lagcoal_ld_involved = L1.coal_ld_involved;
gen coalitionvote = .;
replace coalitionvote = convote if lagcoal_con_involved == 1;
replace coalitionvote = labvote if lagcoal_lab_involved == 1;
replace coalitionvote = ldvote if lagcoal_ld_involved == 1;
replace coalitionvote = convote + labvote if lagcoal_con_involved == 1 & lagcoal_lab_involved == 1;
replace coalitionvote = convote + ldvote if lagcoal_con_involved == 1 & lagcoal_ld_involved == 1;
replace coalitionvote = labvote + ldvote if lagcoal_lab_involved == 1 & lagcoal_ld_involved == 1;
replace coalitionvote = convote + labvote + ldvote if lagcoal_con_involved == 1 & lagcoal_lab_involved == 1 & lagcoal_ld_involved == 1;
replace support4incumbent = coalitionvote if lagcontrol == 4 & support4incumbent == . & coalitionvote ~= .;

/* Generate a variable containing this year's value of support for the incumbent */
/* or next year's if this year there is no election */
gen supp4incumbent2 = .;
replace supp4incumbent2 = support4incumbent if support4incumbent ~= .;
gen f1support4incumbent = F1.support4incumbent;
replace supp4incumbent2 = f1support4incumbent if support4incumbent == . & f1support4incumbent ~= .;
/* Generate a variable containing this year's value of support for the incumbent */
/* or next year's if this year there is no election or the one from in two years */
/* if there is no election this and next year */
gen supp4incumbent3 = supp4incumbent2;
gen f2support4incumbent = F2.support4incumbent;
replace supp4incumbent3 = f2support4incumbent if support4incumbent == . & f1support4incumbent == . & f2support4incumbent ~= .;
/* Generate a variable containing next year's value of support for the incumbent or */
/* the value from in two years if there is no election next year */
gen f1_f2supp4incumbent = f1support4incumbent;
replace f1_f2supp4incumbent = f2support4incumbent if f1support4incumbent == .;
/* Generate a variable containing next year's value of support for the incumbent or */
/* the value from in two years if there is no election next year or the value from */
/* in three years if there is no election next year or in two years */
gen f3support4incumbent = F3.support4incumbent;
gen f1thruf3supp4incumbent = f1_f2supp4incumbent;
replace f1thruf3supp4incumbent = f3support4incumbent if f1_f2supp4incumbent == .;
sort lacode year;
save, replace;

/* Generate a variable "% support for current incumbent in previous election" */
/* (This variable is called "lagsupport4inc".) */
gen lagsupport4inc = .;
gen l1elec = L1.elec;
gen l2elec = L2.elec;
gen l3elec = L3.elec;
gen l4elec = L4.elec;
gen l1convote = L1.convote;
gen l2convote = L2.convote;
gen l3convote = L3.convote;
gen l4convote = L4.convote;
gen l1labvote = L1.labvote;
gen l2labvote = L2.labvote;
gen l3labvote = L3.labvote;
gen l4labvote = L4.labvote;
gen l1ldvote = L1.ldvote;
gen l2ldvote = L2.ldvote;
gen l3ldvote = L3.ldvote;
gen l4ldvote = L4.ldvote;
replace lagsupport4inc = l1convote if (elec == 1 | elec == 2) & lagcontrol == 1 & (l1elec == 1 | l1elec == 2);
replace lagsupport4inc = l2convote if (elec == 1 | elec == 2) & lagcontrol == 1 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec == 1 | l2elec == 2);
replace lagsupport4inc = l3convote if (elec == 1 | elec == 2) & lagcontrol == 1 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec ~= 1 & l2elec ~= 2) & (l3elec == 1 | l3elec == 2);
replace lagsupport4inc = l4convote if (elec == 1 | elec == 2) & lagcontrol == 1 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec ~= 1 & l2elec ~= 2) & (l3elec ~= 1 & l3elec ~= 2) & (l4elec == 1 | l4elec == 2);
replace lagsupport4inc = l1labvote if (elec == 1 | elec == 2) & lagcontrol == 2 & (l1elec == 1 | l1elec == 2);
replace lagsupport4inc = l2labvote if (elec == 1 | elec == 2) & lagcontrol == 2 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec == 1 | l2elec == 2);
replace lagsupport4inc = l3labvote if (elec == 1 | elec == 2) & lagcontrol == 2 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec ~= 1 & l2elec ~= 2) & (l3elec == 1 | l3elec == 2);
replace lagsupport4inc = l4labvote if (elec == 1 | elec == 2) & lagcontrol == 2 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec ~= 1 & l2elec ~= 2) & (l3elec ~= 1 & l3elec ~= 2) & (l4elec == 1 | l4elec == 2);
replace lagsupport4inc = l1ldvote if (elec == 1 | elec == 2) & lagcontrol == 3 & (l1elec == 1 | l1elec == 2);
replace lagsupport4inc = l2ldvote if (elec == 1 | elec == 2) & lagcontrol == 3 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec == 1 | l2elec == 2);
replace lagsupport4inc = l3ldvote if (elec == 1 | elec == 2) & lagcontrol == 3 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec ~= 1 & l2elec ~= 2) & (l3elec == 1 | l3elec == 2);
replace lagsupport4inc = l4ldvote if (elec == 1 | elec == 2) & lagcontrol == 3 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec ~= 1 & l2elec ~= 2) & (l3elec ~= 1 & l3elec ~= 2) & (l4elec == 1 | l4elec == 2);
replace lagsupport4inc = l1convote if lagcoal_con_involved == 1 & lagcontrol == 4 & (l1elec == 1 | l1elec == 2);
replace lagsupport4inc = l2convote if lagcoal_con_involved == 1 & lagcontrol == 4 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec == 1 | l2elec == 2);
replace lagsupport4inc = l3convote if lagcoal_con_involved == 1 & lagcontrol == 4 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec ~= 1 & l2elec ~= 2) & (l3elec == 1 | l3elec == 2);
replace lagsupport4inc = l4convote if lagcoal_con_involved == 1 & lagcontrol == 4 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec ~= 1 & l2elec ~= 2) & (l3elec ~= 1 & l3elec ~= 2) & (l4elec == 1 | l4elec == 2);
replace lagsupport4inc = l1labvote if lagcoal_lab_involved == 1 & lagcontrol == 4 & (l1elec == 1 | l1elec == 2);
replace lagsupport4inc = l2labvote if lagcoal_lab_involved == 1 & lagcontrol == 4 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec == 1 | l2elec == 2);
replace lagsupport4inc = l3labvote if lagcoal_lab_involved == 1 & lagcontrol == 4 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec ~= 1 & l2elec ~= 2) & (l3elec == 1 | l3elec == 2);
replace lagsupport4inc = l4labvote if lagcoal_lab_involved == 1 & lagcontrol == 4 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec ~= 1 & l2elec ~= 2) & (l3elec ~= 1 & l3elec ~= 2) & (l4elec == 1 | l4elec == 2);
replace lagsupport4inc = l1ldvote if lagcoal_ld_involved == 1 & lagcontrol == 4 & (l1elec == 1 | l1elec == 2);
replace lagsupport4inc = l2ldvote if lagcoal_ld_involved == 1 & lagcontrol == 4 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec == 1 | l2elec == 2);
replace lagsupport4inc = l3ldvote if lagcoal_ld_involved == 1 & lagcontrol == 4 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec ~= 1 & l2elec ~= 2) & (l3elec == 1 | l3elec == 2);
replace lagsupport4inc = l4ldvote if lagcoal_ld_involved == 1 & lagcontrol == 4 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec ~= 1 & l2elec ~= 2) & (l3elec ~= 1 & l3elec ~= 2) & (l4elec == 1 | l4elec == 2);
replace lagsupport4inc = l1convote + l1labvote if lagcoal_con_involved == 1 & lagcoal_lab_involved == 1 & lagcontrol == 4 & (l1elec == 1 | l1elec == 2);
replace lagsupport4inc = l2convote + l2labvote if lagcoal_con_involved == 1 & lagcoal_lab_involved == 1 & lagcontrol == 4 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec == 1 | l2elec == 2);
replace lagsupport4inc = l3convote + l3labvote if lagcoal_con_involved == 1 & lagcoal_lab_involved == 1 & lagcontrol == 4 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec ~= 1 & l2elec ~= 2) & (l3elec == 1 | l3elec == 2);
replace lagsupport4inc = l4convote + l4labvote if lagcoal_con_involved == 1 & lagcoal_lab_involved == 1 & lagcontrol == 4 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec ~= 1 & l2elec ~= 2) & (l3elec ~= 1 & l3elec ~= 2) & (l4elec == 1 | l4elec == 2);
replace lagsupport4inc = l1convote + l1ldvote if lagcoal_con_involved == 1 & lagcoal_ld_involved == 1 & lagcontrol == 4 & (l1elec == 1 | l1elec == 2);
replace lagsupport4inc = l2convote + l2ldvote if lagcoal_con_involved == 1 & lagcoal_ld_involved == 1 & lagcontrol == 4 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec == 1 | l2elec == 2);
replace lagsupport4inc = l3convote + l3ldvote if lagcoal_con_involved == 1 & lagcoal_ld_involved == 1 & lagcontrol == 4 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec ~= 1 & l2elec ~= 2) & (l3elec == 1 | l3elec == 2);
replace lagsupport4inc = l4convote + l4ldvote if lagcoal_con_involved == 1 & lagcoal_ld_involved == 1 & lagcontrol == 4 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec ~= 1 & l2elec ~= 2) & (l3elec ~= 1 & l3elec ~= 2) & (l4elec == 1 | l4elec == 2);
replace lagsupport4inc = l1labvote + l1ldvote if lagcoal_lab_involved == 1 & lagcoal_ld_involved == 1 & lagcontrol == 4 & (l1elec == 1 | l1elec == 2);
replace lagsupport4inc = l2labvote + l2ldvote if lagcoal_lab_involved == 1 & lagcoal_ld_involved == 1 & lagcontrol == 4 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec == 1 | l2elec == 2);
replace lagsupport4inc = l3labvote + l3ldvote if lagcoal_lab_involved == 1 & lagcoal_ld_involved == 1 & lagcontrol == 4 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec ~= 1 & l2elec ~= 2) & (l3elec == 1 | l3elec == 2);
replace lagsupport4inc = l4labvote + l4ldvote if lagcoal_lab_involved == 1 & lagcoal_ld_involved == 1 & lagcontrol == 4 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec ~= 1 & l2elec ~= 2) & (l3elec ~= 1 & l3elec ~= 2) & (l4elec == 1 | l4elec == 2);
replace lagsupport4inc = l1convote + l1labvote + l1ldvote if lagcoal_con_involved == 1 & lagcoal_lab_involved == 1 & lagcoal_ld_involved == 1 & lagcontrol == 4 & (l1elec == 1 | l1elec == 2);
replace lagsupport4inc = l2convote + l2labvote + l2ldvote if lagcoal_con_involved == 1 & lagcoal_lab_involved == 1 & lagcoal_ld_involved == 1 & lagcontrol == 4 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec == 1 | l2elec == 2);
replace lagsupport4inc = l3convote + l3labvote + l3ldvote if lagcoal_con_involved == 1 & lagcoal_lab_involved == 1 & lagcoal_ld_involved == 1 & lagcontrol == 4 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec ~= 1 & l2elec ~= 2) & (l3elec == 1 | l3elec == 2);
replace lagsupport4inc = l4convote + l4labvote + l4ldvote if lagcoal_con_involved == 1 & lagcoal_lab_involved == 1 & lagcoal_ld_involved == 1 & lagcontrol == 4 & (l1elec ~= 1 & l1elec ~= 2) & (l2elec ~= 1 & l2elec ~= 2) & (l3elec ~= 1 & l3elec ~= 2) & (l4elec == 1 | l4elec == 2);
lab var lagsupport4inc "% support for current incumbent in previous election";
gen f1thruf3lagsupport4inc = .;
replace f1thruf3lagsupport4inc = F1.lagsupport4inc if f1support4incumbent ~= .;
replace f1thruf3lagsupport4inc = F2.lagsupport4inc if f1support4incumbent == . & f2support4incumbent ~= .;
replace f1thruf3lagsupport4inc = F3.lagsupport4inc if f1support4incumbent == . & f2support4incumbent == . & f3support4incumbent ~= .;
lab var f1thruf3lagsupport4inc "% support for current incumbent in last election";

/* Generate a variable indicating the closeness of the LAST election */
/* (This variable is called "diff2maxpartieslast".) */
egen maxpartyvote = rmax(convote greenvote indvote labvote ldvote);
lab var maxpartyvote "largest party vote share";
gen convote2 = convote;
replace convote2 = . if convote == maxpartyvote;
gen greenvote2 = greenvote;
replace greenvote2 = . if greenvote == maxpartyvote;
gen indvote2 = indvote;
replace indvote2 = . if indvote == maxpartyvote;
gen labvote2 = labvote;
replace labvote2 = . if labvote == maxpartyvote;
gen ldvote2 = ldvote;
replace ldvote2 = . if ldvote == maxpartyvote;
egen secondpartyvote = rmax(convote2 greenvote2 indvote2 labvote2 ldvote2);
lab var secondpartyvote "second largest party vote share";
gen diff2biggestparties = maxpartyvote - secondpartyvote;
lab var diff2biggestparties "Diff. btw. vote share of 2 biggest parties THIS election";
gen diff2maxpartieslast = .;
replace diff2maxpartieslast = L1.diff2biggestparties if (l1elec == 1 | l1elec == 2);
replace diff2maxpartieslast = L2.diff2biggestparties if (l1elec ~= 1 & l1elec ~= 2) & (l2elec == 1 | l2elec == 2);
replace diff2maxpartieslast = L3.diff2biggestparties if (l1elec ~= 1 & l1elec ~= 2) & (l2elec ~= 1 & l2elec ~= 2) & (l3elec == 1 | l3elec == 2);
replace diff2maxpartieslast = L4.diff2biggestparties if (l1elec ~= 1 & l1elec ~= 2) & (l2elec ~= 1 & l2elec ~= 2) & (l3elec ~= 1 & l3elec ~= 2) & (l4elec == 1 | l4elec == 2);
lab var diff2maxpartieslast "Diff. btw. vote share of 2 biggest parties LAST election";
gen f1thruf3diff2maxpartieslast = .;
replace f1thruf3diff2maxpartieslast = F1.diff2maxpartieslast if f1support4incumbent ~= .;
replace f1thruf3diff2maxpartieslast = F2.diff2maxpartieslast if f1support4incumbent == . & f2support4incumbent ~= .;
replace f1thruf3diff2maxpartieslast = F3.diff2maxpartieslast if f1support4incumbent == . & f2support4incumbent == . & f3support4incumbent ~= .;
lab var f1thruf3diff2maxpartieslast "Diff. btw. vote share of 2 biggest parties LAST election";

/* Generate a dummy variable for whole-council elections (as opposed to thirds) */
/* (This variable is called "wholecouncil".) */
gen wholecouncil = .;
replace wholecouncil = 1 if elec == 1;
replace wholecouncil = 0 if elec == 2;
lab var wholecouncil "Whole-council election (dummy)";
gen f1thruf3wholecouncil = .;
replace f1thruf3wholecouncil = F1.wholecouncil if f1support4incumbent ~= .;
replace f1thruf3wholecouncil = F2.wholecouncil if f1support4incumbent == . & f2support4incumbent ~= .;
replace f1thruf3wholecouncil = F3.wholecouncil if f1support4incumbent == . & f2support4incumbent == . & f3support4incumbent ~= .;
lab var f1thruf3wholecouncil "whole council election (dummy)";

# delimit cr;

* Make claimant rate variable for the satisfaction models
gen f1thruf3q1claimrate = .
replace f1thruf3q1claimrate = F1.q1claimrate if f1support4incumbent ~= .
replace f1thruf3q1claimrate = F2.q1claimrate if f1support4incumbent == . /*
*/ & f2support4incumbent ~= .
replace f1thruf3q1claimrate = F3.q1claimrate if f1support4incumbent == . /*
*/ & f2support4incumbent == . & f3support4incumbent ~= .
lab var f1thruf3q1claimrate "Ave. 1st-qtr. claimant rate"
save, replace

* Make level of council tax variable for the satisfaction models
gen f1thruf3counciltax = .
replace f1thruf3counciltax = F1.counciltax if f1support4incumbent ~= .
replace f1thruf3counciltax = F2.counciltax if f1support4incumbent == . /*
*/ & f2support4incumbent ~= .
replace f1thruf3counciltax = F3.counciltax if f1support4incumbent == . /*
*/ & f2support4incumbent == . & f3support4incumbent ~= .
lab var f1thruf3counciltax "Ave. council tax/dwelling (in �)"
save, replace

* Generate first difference of council tax
gen d1counciltax = D1.counciltax
lab var d1counciltax "Chg. in ave. c. tax/dwelling (in �)"

* Make first difference of council tax variable for the satisfaction models
gen f1thruf3d1counciltax = .
replace f1thruf3d1counciltax = F1.d1counciltax if f1support4incumbent ~= .
replace f1thruf3d1counciltax = F2.d1counciltax if f1support4incumbent == . /*
*/ & f2support4incumbent ~= .
replace f1thruf3d1counciltax = F3.d1counciltax if f1support4incumbent == . /*
*/ & f2support4incumbent == . & f3support4incumbent ~= .
lab var f1thruf3d1counciltax "Chg. in ave. c. tax/dwelling (in �)"
save, replace

* Make lag of performance indicators
* (The service performance score is called "sp_per" and the 
*  CPA is called "cpa".)
gen l1sp_per = L1.sp_per
lab var l1sp_per "Lag of service perf. score"
gen l1cpa = L1.cpa
lab var l1cpa "Lag of CPA score"
tab l1cpa, gen(l1cpa)
rename l1cpa1 l1cpa0
rename l1cpa2 l1cpa1
rename l1cpa3 l1cpa2
rename l1cpa4 l1cpa3
rename l1cpa5 l1cpa4
lab var l1cpa0 "Lag of CPA 0 stars (dummy)"
lab var l1cpa1 "Lag of CPA 1 stars (dummy)"
lab var l1cpa2 "Lag of CPA 2 stars (dummy)"
lab var l1cpa3 "Lag of CPA 3 stars (dummy)"
lab var l1cpa4 "Lag of CPA 4 stars (dummy)"
gen l1cpa3and4 = .
replace l1cpa3and4 = 0 if l1cpa0 == 1 | l1cpa1 == 1 | l1cpa2 == 1
replace l1cpa3and4 = 1 if l1cpa3 == 1 | l1cpa4 == 1
lab var l1cpa3and4 "Lag of CPA 3 or 4 stars (dummy)"
tab l1cpa l1cpa3and4
gen l1cpa0and1 = .
replace l1cpa0and1 = 1 if l1cpa0 == 1 | l1cpa1 == 1
replace l1cpa0and1 = 0 if l1cpa2 == 1 | l1cpa3 == 1 | l1cpa4 == 1
lab var l1cpa0and1 "Lag of CPA 0 stars or 1 star (dummy)"

* Make political party control indicators
gen labourcouncil = .
replace labourcouncil = 1 if polcontrol == 2
replace labourcouncil = 0 if polcontrol == 1 | polcontrol == 3 | polcontrol == 4
lab var labourcouncil "Labour controls council (dummy)"
gen torycouncil = .
replace torycouncil = 1 if polcontrol == 1
replace torycouncil = 0 if polcontrol == 2 | polcontrol == 3 | polcontrol == 4
lab var torycouncil "Tories control council (dummy)"
gen libdemcouncil = .
replace libdemcouncil = 1 if polcontrol == 3
replace libdemcouncil = 0 if polcontrol == 1 | polcontrol == 2 | polcontrol == 4
lab var libdemcouncil "Lib Dems control council (dummy)"

* Make onset of political party control indicators
gen labouronset = .
replace labouronset = 1 if polcontrol == 2 & lagcontrol ~= 2 & lagcontrol ~= .
replace labouronset = 0 if polcontrol == 1 | polcontrol == 3 | polcontrol == 4 | /*
*/ lagcontrol == 2
lab var labouronset "Change to Labour control (dummy)"
gen toryonset = .
replace toryonset = 1 if polcontrol == 1 & lagcontrol ~= 1 & lagcontrol ~= .
replace toryonset = 0 if polcontrol == 2 | polcontrol == 3 | polcontrol == 4 | /*
*/ lagcontrol == 1
lab var toryonset "Change to Tory control (dummy)"
gen libdemonset = .
replace libdemonset = 1 if polcontrol == 3 & lagcontrol ~= 3 & lagcontrol ~= .
replace libdemonset = 0 if polcontrol == 1 | polcontrol == 2 | polcontrol == 4 | /*
*/ lagcontrol == 3
lab var libdemonset "Change to Lib Dem control (dummy)"
gen noconset = .
replace noconset = 1 if polcontrol == 4 & lagcontrol ~= 4 & lagcontrol ~= .
replace noconset = 0 if polcontrol == 1 | polcontrol == 2 | polcontrol == 3 | /*
*/ lagcontrol == 4
lab var noconset "Change to NOC (dummy)"

* Make lag of Labour party control indicator
gen laglabourcontrol = .
replace laglabourcontrol = 1 if lagcontrol == 2
replace laglabourcontrol = 0 if lagcontrol == 1 | lagcontrol == /*
*/ 3 | lagcontrol == 4
lab var laglabourcontrol "Labour control before elec. (dummy)"
gen f1thruf3laglabourcontrol = .
replace f1thruf3laglabourcontrol = F1.laglabourcontrol if f1support4incumbent ~= .
replace f1thruf3laglabourcontrol = F2.laglabourcontrol if f1support4incumbent == . /*
*/ & f2support4incumbent ~= .
replace f1thruf3laglabourcontrol = F3.laglabourcontrol if f1support4incumbent == . /*
*/ & f2support4incumbent == . & f3support4incumbent ~= .
lab var f1thruf3laglabourcontrol "Labour control before elec. (dummy)"

* Make lag of LD party control indicator
gen laglibdemcontrol = .
replace laglibdemcontrol = 1 if lagcontrol == 3
replace laglibdemcontrol = 0 if lagcontrol == 1 | lagcontrol == /*
*/ 2 | lagcontrol == 4
lab var laglibdemcontrol "LD control before elec. (dummy)"
gen f1thruf3laglibdemcontrol = .
replace f1thruf3laglibdemcontrol = F1.laglibdemcontrol if f1support4incumbent ~= .
replace f1thruf3laglibdemcontrol = F2.laglibdemcontrol if f1support4incumbent == . /*
*/ & f2support4incumbent ~= .
replace f1thruf3laglibdemcontrol = F3.laglibdemcontrol if f1support4incumbent == . /*
*/ & f2support4incumbent == . & f3support4incumbent ~= .
lab var f1thruf3laglibdemcontrol "LD control before elec. (dummy)"

* Make indicator for 1-party control right before election
gen clearresp = .
replace clearresp = 1 if lagcontrol == 1 | lagcontrol == 2 | lagcontrol == 3
replace clearresp = 0 if lagcontrol == 4
lab var clearresp "1-party control before elec. (dummy)"
sum clearresp if support4incumbent ~= .
sort year
by year: sum clearresp if support4incumbent ~= .
sort lacode year
save, replace
gen f1thruf3clearresp = .
replace f1thruf3clearresp = F1.clearresp if f1support4incumbent ~= .
replace f1thruf3clearresp = F2.clearresp if f1support4incumbent == . /*
*/ & f2support4incumbent ~= .
replace f1thruf3clearresp = F3.clearresp if f1support4incumbent == . /*
*/ & f2support4incumbent == . & f3support4incumbent ~= .
lab var f1thruf3clearresp "1-party control before elec. (dummy)"

* Generate second lags and difference between one-year lag and
* two-year lag of the service performance score
gen l2sp_per = L2.sp_per
lab var l2sp_per "2-yr. lag of service perf. score"
gen d1l1sp_per = D1.l1sp_per
lab var d1l1sp_per "1st diff. of lagged serv. perf. score"

* Generate first differences of CPA
gen d1cpa = D1.cpa
lab var d1cpa "Change in CPA score from t-1 to t"
gen d1l1cpa = D1.l1cpa
lab var d1l1cpa "Change in CPA score from t-2 to t-1"

* Generate std. deviation of the service performance score and
* citizen satisfaction
gen sdl1sp_per = .
sort lacode
forval j = 1(1)102 {
    by lacode: egen sdl1sp_per_`j' = sd(l1sp_per) if lacode == `j'
    replace sdl1sp_per = sdl1sp_per_`j' if sdl1sp_per_`j' ~= .
}
forval j = 341(1)386 {
    by lacode: egen sdl1sp_per_`j' = sd(l1sp_per) if lacode == `j'
    replace sdl1sp_per = sdl1sp_per_`j' if sdl1sp_per_`j' ~= .
}
forval j = 1(1)102 {
    drop sdl1sp_per_`j'
}
forval j = 341(1)386 {
    drop sdl1sp_per_`j'
}
replace sdl1sp_per = . if year < 2004
lab var sdl1sp_per "Std. dev. of lagged serv. perf. score"
sort year
by year: sum sdl1sp_per
gen sd_3 = .
sort lacode
forval j = 1(1)102 {
    by lacode: egen sd_3_`j' = sd(_3) if lacode == `j'
    replace sd_3 = sd_3_`j' if sd_3_`j' ~= .
  }
forval j = 341(1)386 {
    by lacode: egen sd_3_`j' = sd(_3) if lacode == `j'
    replace sd_3 = sd_3_`j' if sd_3_`j' ~= .
  }
forval j = 1(1)102 {
    drop sd_3_`j'
}
forval j = 341(1)386 {
    drop sd_3_`j'
}
replace sd_3 = . if year < 2000
replace sd_3 = . if year == 2001 | year == 2002 | year == 2004 | year == 2005 | year == 2007
lab var sd_3 "Std. dev. of citizen satisfaction"
sort year
by year: sum _3 sd_3

* Generate various performance change indicators
gen sp_per_1_3_sd = .
replace sp_per_1_3_sd = 0 if d1l1sp_per ~= .
replace sp_per_1_3_sd = 1 if abs(d1l1sp_per) > (1/3) * sdl1sp_per & d1l1sp_per ~= .
lab var sp_per_1_3_sd "Some (>(1/3)sd) chg. L2.sp_per to L1.sp_per"
gen sp_per_large = .
replace sp_per_large = 0 if d1l1sp_per ~= .
replace sp_per_large = 1 if abs(d1l1sp_per) > 1 * sdl1sp_per & d1l1sp_per ~= .
lab var sp_per_large "Large (>1sd) chg. L2.sp_per to L1.sp_per"
gen sp_per_verylarge = .
replace sp_per_verylarge = 0 if d1l1sp_per ~= .
replace sp_per_verylarge = 1 if abs(d1l1sp_per) > 2 * sdl1sp_per & d1l1sp_per ~= .
lab var sp_per_verylarge "Very large (>2sd) chg. L2.sp_per to L1.sp_per"
gen sp_per_percpast = 100*(l1sp_per/l2sp_per)
lab var sp_per_percpast "% change from L2.sp_per to L1.sp_per"
gen cpachange = .
replace cpachange = 0 if d1l1cpa == 0
replace cpachange = 1 if d1l1cpa ~= 0 & d1l1cpa ~= .
lab var cpachange "Change in CPA score from t-2 to t-1 (dummy)"
gen sp_per_neg1_3_sd = sp_per_1_3_sd
replace sp_per_neg1_3_sd = 0 if d1l1sp_per > 0 & d1l1sp_per ~= .
lab var sp_per_neg1_3_sd "Some (>(1/3)sd) worsening of sp_per"
gen sp_per_pos1_3_sd = sp_per_1_3_sd
replace sp_per_pos1_3_sd = 0 if d1l1sp_per < 0 & d1l1sp_per ~= .
lab var sp_per_pos1_3_sd "Some (>(1/3)sd) improvement of sp_per"
gen sp_per_neglarge = sp_per_large
replace sp_per_neglarge = 0 if d1l1sp_per > 0 & d1l1sp_per ~= .
lab var sp_per_neglarge "Large (>1sd) worsening of sp_per"
gen sp_per_poslarge = sp_per_large
replace sp_per_poslarge = 0 if d1l1sp_per < 0 & d1l1sp_per ~= .
lab var sp_per_poslarge "Large (>1sd) improvement of sp_per"
gen sp_per_negverylarge = sp_per_verylarge
replace sp_per_negverylarge = 0 if d1l1sp_per > 0 & d1l1sp_per ~= .
lab var sp_per_negverylarge "Very large (>2sd) worsening of sp_per"
gen sp_per_negpercpast = 1 if sp_per_percpast ~= .
replace sp_per_negpercpast = 0 if d1l1sp_per > 0 & d1l1sp_per ~= .
lab var sp_per_negpercpast "sp_per got worse from 2 yrs. ago to last year"
gen cpanegchange = cpachange
replace cpanegchange = 0 if d1l1cpa >= 0 & d1l1cpa ~= .
replace cpanegchange = 1 if d1l1cpa < 0 & d1l1cpa ~= .
lab var cpanegchange "CPA score got worse from t-2 to t-1 (dummy)"
gen cpaimproved = cpachange
replace cpaimproved = 0 if d1l1cpa <= 0 & d1l1cpa ~= .
replace cpaimproved = 1 if d1l1cpa > 0 & d1l1cpa ~= .
lab var cpaimproved "CPA score got better from t-2 to t-1 (dummy)"
gen cpaup2 = .
replace cpaup2 = 0 if d1l1cpa <= 1 & d1l1cpa ~= .
replace cpaup2 = 1 if d1l1cpa > 1 & d1l1cpa ~= .
lab var cpaup2 "CPA score up 2 or more stars from t-2 to t-1 (dummy)"
save, replace

* Homevoter test
* Average price of dwelling in L.A. in thousands of pounds ("all_gbp"):
sort lacode year
gen l1all_gbpK = L1.all_gbp / 1000
gen f1thruf3l1all_gbpK = .
replace f1thruf3l1all_gbpK = F1.l1all_gbpK if f1support4incumbent ~= .
replace f1thruf3l1all_gbpK = F2.l1all_gbpK if f1support4incumbent == . /*
*/ & f2support4incumbent ~= .
replace f1thruf3l1all_gbpK = F3.l1all_gbpK if f1support4incumbent == . /*
*/ & f2support4incumbent == . & f3support4incumbent ~= .
save, replace

save workfile2, replace
keep lacode year _3 sd_3
keep if year == 2000 | year == 2003 | year == 2006
gen period = .
replace period = 1 if year == 2000
replace period = 2 if year == 2003
replace period = 3 if year == 2006
sort lacode period
xtset lacode period, yearly
save, replace
gen l1_3 = L1._3
lab var l1_3 "Satisfaction 3 years ago"
gen d1_3 = D1._3
lab var d1_3 "Change from sat. 3 yrs. ago to this time"
gen _3large = .
replace _3large = 0 if d1_3 ~= .
replace _3large = 1 if abs(d1_3) > 1 * sd_3 & d1_3 ~= .
lab var _3large "Large (>1sd) chg. between waves of sat. survey"
gen _3percpast = 100*(_3/l1_3)
lab var _3percpast "% chg. between waves of sat. survey"
gen _3neglarge = _3large
replace _3neglarge = 0 if d1_3 > 0 & d1_3 ~= .
lab var _3neglarge "Large (>1sd) worsening btw. waves of sat. survey"
gen _3negpercpast = 1 if _3percpast ~= .
replace _3negpercpast = 0 if d1_3 > 0 & d1_3 ~= .
lab var _3negpercpast "Worsening btw. waves of sat. survey"
compress
sort lacode year
save, replace
xtset lacode year, yearly
sort lacode year
save, replace
use workfile, clear
sort lacode year
save, replace
merge lacode year using workfile2
tab _merge
drop _merge period
compress
sort lacode year
save workfile, replace
erase workfile2.dta
xtset lacode year, yearly
save, replace

***
* The data analysis starts here.  
*******

* (1) sp_per

* (1.1) Proportionate response to performance model

* (1.1) non-interactive model

* Note: Here and later on, I do the Hausman tests of H0: "FE and RE have similar coefficient vectors" 
* using auxiliary model runs.  These auxiliary model runs are preceded by the command "quietly", which 
* means that no output is shown.  I have to do auxiliary model runs because the Hausman test requires a 
* regular variance-covariance estimator, whereas in the article I report Huber-White estimates.  

* Hausman test
quietly xtreg support4incumbent l1sp_per diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax /* 
*/ y2004 y2005 y2006 y2007, fe
est store FE1_1

quietly xtreg support4incumbent l1sp_per diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax /* 
*/ y2004 y2005 y2006 y2007, re
est store RE1_1

* (1.1) Hausman test result
hausman FE1_1 RE1_1

* (1.1) serial correlation?
 dis "Wooldridge test of H0: no serial correlation:"
 * xtserial support4incumbent, output

* Page 1277: Table 1, proportional model
xtreg support4incumbent l1sp_per diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax /* 
*/ y2004 y2005 y2006 y2007, fe cluster(lacode)

sum support4incumbent if e(sample) & L1.controlchange == 1
sum support4incumbent if e(sample) & L1.controlchange == 0 & L1.elec == 0 /*
*/ & L2.controlchange == 1
sum support4incumbent if e(sample) & L1.controlchange == 0 & L1.elec == 0 /*
*/ & L2.elec == 0 & L2.controlchange == 0 & L3.controlchange == 1

gen esample1_1 = 1 if e(sample)

* for results discussion
sort year
by year: tab l1cpa if e(sample)
sort lacode year

* check something Peter asked about
corr counciltax l1cpa if e(sample)
corr counciltax cpa if e(sample)

* Look at the dependent variable

xtsum newceo if e(sample)
 dis r(sd_w)
 dis r(sd)
 dis 100*(r(sd_w)^2 / r(sd)^2) // approx. % within variation (% of total variation)
 dis 100*(r(sd_b)^2 / r(sd)^2) // approx. % between variation (% of total variation)

* Page 1282: Footnote 8: "We also tried estimating all models as conditional models. First,
* we augmented them with multiplicative terms testing whether
* the performance variables are moderated by the closeness of the
* previous election result (the percentage point difference in votes
* between the two largest parties), yet only in two cases could the
* null hypothesis of no interactions be rejected."

gen interaction = l1sp_per * diff2maxpartieslast
quietly xtreg support4incumbent l1sp_per interaction diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax /* 
*/ y2004 y2005 y2006 y2007, fe cluster(lacode)
test interaction
drop interaction

* Make table of summary statistics (Appendix, Table A1)
sum support4incumbent l1sp_per l1cpa l1cpa2 l1cpa3and4 l1cpa0and1 diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax if esample1_1 == 1
gen torypercent = 100 * (tory_seats/seats)
gen libdempercent = 100 * (ldp_seats/seats)
sum L1.torypercent if laglabourcontrol == 1 & esample1_1 == 1
sum L1.libdempercent if laglabourcontrol == 1 & esample1_1 == 1

* Get correlation of dependent variables:
corr l1sp_per l1cpa if esample1_1 == 1

* Rerun threshold model from Table 2 with individual CPA categories (Appendix, Table A2)

* "reward formulation"
xtreg support4incumbent l1cpa4 l1cpa3 l1cpa2 l1cpa1 diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax /* 
*/ y2004 y2005 y2006 y2007 if esample1_1 == 1, fe cluster(lacode)

* Test H0: "Performance doesn't matter"
test l1cpa1 l1cpa2 l1cpa3 l1cpa4

dis "Do the higher CPA categories 'bring the same reward'?"
test l1cpa2=l1cpa3=l1cpa4

* "extremes formulation"
xtreg support4incumbent l1cpa4 l1cpa3 l1cpa1 l1cpa0 diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax /* 
*/ y2004 y2005 y2006 y2007 if esample1_1 == 1, fe cluster(lacode)

* Test H0: "Performance doesn't matter"
test l1cpa0 l1cpa1 l1cpa3 l1cpa4

dis "Is poor and weak the same?"
test l1cpa0=l1cpa1

* Make CPA figure (appendix, Figure A1)

label var esample1_1 CPA

lab def l1cpa 0 "0 (Poor)" 1 "1 (Weak)" 2 "2 (Fair)" 3 "3 (Good)" 4 "4 (Excellent)"
lab val l1cpa l1cpa

graph bar (count) esample1_1 if esample1_1 == 1, over(l1cpa) ytitle("")
translate @Graph JOP-CPAgraph.wmf, replace

* (1.2) Non-proportionate: performance decline relative to the past model

* (1.2) non-interactive model

* Hausman test
quietly xtreg support4incumbent sp_per_pos1_3_sd sp_per_neg1_3_sd diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax /* 
*/ y2005 y2006 y2007, fe
est store FE1_2

quietly xtreg support4incumbent sp_per_pos1_3_sd sp_per_neg1_3_sd diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax /* 
*/ y2005 y2006 y2007, re
est store RE1_2

* (1.2) Hausman test result
hausman FE1_2 RE1_2

* Page 1277: Table 1, positivity-negativity model
xtreg support4incumbent sp_per_pos1_3_sd sp_per_neg1_3_sd diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax /* 
*/ y2005 y2006 y2007, fe cluster(lacode)

corr sp_per_pos1_3_sd cpaimproved if e(sample)
sort year
by year: tab sp_per_pos1_3_sd if e(sample)
by year: tab sp_per_pos1_3_sd cpaimproved if e(sample)
by year: list lacode l1cpa cpaimproved if sp_per_pos1_3_sd == 1 & e(sample)
sort lacode year

* Page 1282: Footnote 8: "We also tried estimating all models as conditional models. First,
* we augmented them with multiplicative terms testing whether
* the performance variables are moderated by the closeness of the
* previous election result (the percentage point difference in votes
* between the two largest parties), yet only in two cases could the
* null hypothesis of no interactions be rejected."

gen interaction1 = sp_per_pos1_3_sd * diff2maxpartieslast
gen interaction2 = sp_per_neg1_3_sd * diff2maxpartieslast
quietly xtreg support4incumbent sp_per_pos1_3_sd sp_per_neg1_3_sd diff2maxpartieslast /*
*/ interaction1 interaction2 /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax /* 
*/ y2005 y2006 y2007, fe cluster(lacode)
test interaction1 interaction2
drop interaction1 interaction2

* (2) CPA

* (2.1) Threshold model: Reward formulation

* (2.1) non-interactive model

* Hausman test
quietly xtreg support4incumbent l1cpa2 l1cpa3and4 diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax /* 
*/ y2004 y2005 y2006 y2007 if esample1_1 == 1, fe
est store FE2_1

quietly xtreg support4incumbent l1cpa2 l1cpa3and4 diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax /* 
*/ y2004 y2005 y2006 y2007 if esample1_1 == 1, re
est store RE2_1

* (2.1) Hausman test result
hausman FE2_1 RE2_1

* Page 1278: Table 2, threshold model: reward formulation
xtreg support4incumbent l1cpa2 l1cpa3and4 diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax /* 
*/ y2004 y2005 y2006 y2007 if esample1_1 == 1, fe cluster(lacode)

* Test H0: "Performance doesn't matter"
test l1cpa2 l1cpa3and4

dis "Do the higher CPA categories 'bring the same reward'?"
test l1cpa2=l1cpa3and4

* Page 1282: Footnote 8: "We also tried estimating all models as conditional models. First,
* we augmented them with multiplicative terms testing whether
* the performance variables are moderated by the closeness of the
* previous election result (the percentage point difference in votes
* between the two largest parties), yet only in two cases could the
* null hypothesis of no interactions be rejected."

gen interaction1 = l1cpa2 * diff2maxpartieslast
gen interaction2 = l1cpa3and4 * diff2maxpartieslast
quietly xtreg support4incumbent l1cpa2 l1cpa3and4 diff2maxpartieslast /*
*/ interaction1 interaction2 /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax /* 
*/ y2004 y2005 y2006 y2007 if esample1_1 == 1, fe cluster(lacode)
test interaction1 interaction2
drop interaction1 interaction2

* (2.2) Threshold model: Extremes formulation

* (2.2) non-interactive model

* Hausman test
quietly xtreg support4incumbent l1cpa3and4 l1cpa0and1 diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax /* 
*/ y2004 y2005 y2006 y2007 if esample1_1 == 1, fe
est store FE2_2

quietly xtreg support4incumbent l1cpa3and4 l1cpa0and1 diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax /* 
*/ y2004 y2005 y2006 y2007 if esample1_1 == 1, re
est store RE2_2

* (2.2) Hausman test result
hausman FE2_2 RE2_2

* Page 1278: Table 2, threshold model: extremes formulation
xtreg support4incumbent l1cpa3and4 l1cpa0and1 diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax /* 
*/ y2004 y2005 y2006 y2007 if esample1_1 == 1, fe cluster(lacode)

* Test H0: "Performance doesn't matter"
test l1cpa3and4 l1cpa0and1

dis "Do the outlying CPA categories 'have the same effect'?"
test l1cpa3and4=l1cpa0and1

* Page 1282: Footnote 8: "We also tried estimating all models as conditional models. First,
* we augmented them with multiplicative terms testing whether
* the performance variables are moderated by the closeness of the
* previous election result (the percentage point difference in votes
* between the two largest parties), yet only in two cases could the
* null hypothesis of no interactions be rejected."

gen interaction1 = l1cpa3and4 * diff2maxpartieslast
gen interaction2 = l1cpa0and1 * diff2maxpartieslast
quietly xtreg support4incumbent l1cpa3and4 l1cpa0and1 diff2maxpartieslast /*
*/ interaction1 interaction2 /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax /* 
*/ y2004 y2005 y2006 y2007 if esample1_1 == 1, fe cluster(lacode)
test interaction1 interaction2
drop interaction1 interaction2

* (2.3) Positivity and negativity model

* (2.3) non-interactive model

* Hausman test
quietly xtreg support4incumbent cpaimproved cpanegchange diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax /* 
*/ y2005 y2006 y2007, fe
est store FE2_3

quietly xtreg support4incumbent cpaimproved cpanegchange diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax /* 
*/ y2005 y2006 y2007, re
est store RE2_3

* (2.3) Hausman test result
hausman FE2_3 RE2_3

* Page 1278: Table 2, positivity vs. negativity model
xtreg support4incumbent cpaimproved cpanegchange diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax /* 
*/ y2005 y2006 y2007, fe cluster(lacode)

* Test H0: "Performance doesn't matter"
test cpaimproved cpanegchange

dis "Are the coefficients om both types of change the same?"
test cpaimproved=cpanegchange

tab y2004 if e(sample)
tab y2005 if e(sample)
tab y2006 if e(sample)
tab y2007 if e(sample)

* Page 1282: Footnote 8: "We also tried estimating all models as conditional models. First,
* we augmented them with multiplicative terms testing whether
* the performance variables are moderated by the closeness of the
* previous election result (the percentage point difference in votes
* between the two largest parties), yet only in two cases could the
* null hypothesis of no interactions be rejected."

gen interaction1 = cpaimproved * diff2maxpartieslast
gen interaction2 = cpanegchange * diff2maxpartieslast
quietly xtreg support4incumbent cpaimproved cpanegchange diff2maxpartieslast /*
*/ interaction1 interaction2 /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate l1all_gbpK counciltax /* 
*/ y2005 y2006 y2007, fe cluster(lacode)
test interaction1 interaction2
drop interaction1 interaction2

* (3) BV3

* (3.1) Proportionate response to performance model

* (3.1) non-interactive model

* Hausman test
quietly xtreg f1thruf3supp4incumbent _3 f1thruf3diff2maxpartieslast /*
*/ f1thruf3lagsupport4inc f1thruf3laglabourcontrol f1thruf3laglibdemcontrol /*
*/ f1thruf3wholecouncil f1thruf3q1claimrate f1thruf3l1all_gbpK f1thruf3counciltax /* 
*/ y2003 y2006, fe
est store FE3_1

quietly xtreg f1thruf3supp4incumbent _3 f1thruf3diff2maxpartieslast /*
*/ f1thruf3lagsupport4inc f1thruf3laglabourcontrol f1thruf3laglibdemcontrol /*
*/ f1thruf3wholecouncil f1thruf3q1claimrate f1thruf3l1all_gbpK f1thruf3counciltax /* 
*/ y2003 y2006, re
est store RE3_1

* (3.1) Hausman test result
hausman FE3_1 RE3_1

* (3.1) serial correlation?
 dis "Wooldridge test of H0: no serial correlation:"
 * xtserial f1thruf3supp4incumbent, output

* Page 1280: Table 3, Citizen perceptions model
xtreg f1thruf3supp4incumbent _3 f1thruf3diff2maxpartieslast /*
*/ f1thruf3lagsupport4inc f1thruf3laglabourcontrol f1thruf3laglibdemcontrol /*
*/ f1thruf3wholecouncil f1thruf3q1claimrate f1thruf3l1all_gbpK f1thruf3counciltax /* 
*/ y2003 y2006, fe cluster(lacode)

* Get correlations between citizen satisfaction and governmental
* perceptions of performance

corr _3 sp_per if e(sample)

corr _3 cpa if e(sample)

xtline _3 if e(sample), overlay xlabel(2000 2003 2006) legend(off)
translate @Graph BV3esample_timeseries.wmf, replace

* Page 1282: Footnote 8: "We also tried estimating all models as conditional models. First,
* we augmented them with multiplicative terms testing whether
* the performance variables are moderated by the closeness of the
* previous election result (the percentage point difference in votes
* between the two largest parties), yet only in two cases could the
* null hypothesis of no interactions be rejected."

gen interaction = _3 * f1thruf3diff2maxpartieslast
quietly xtreg f1thruf3supp4incumbent _3 interaction f1thruf3diff2maxpartieslast /*
*/ f1thruf3lagsupport4inc f1thruf3laglabourcontrol f1thruf3laglibdemcontrol /*
*/ f1thruf3wholecouncil f1thruf3q1claimrate f1thruf3l1all_gbpK f1thruf3counciltax /* 
*/ y2003 y2006, fe cluster(lacode)
test interaction
drop interaction

* Page 1281: Main text: "As a robustness
* check, we also estimated a modified version of the
* reward formulation, where the base group is made up
* exclusively of council-years with low performance of
* zero stars before the election."

* "reward formulation"
xtreg support4incumbent l1cpa1 l1cpa2 l1cpa3and4 diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate counciltax /* 
*/ y2004 y2005 y2006 y2007, fe cluster(lacode)

* Test H0: "Performance doesn't matter"
test l1cpa1 l1cpa2 l1cpa3and4

dis "Do the higher CPA categories 'bring the same reward'?"
test l1cpa2=l1cpa3and4

* "extremes formulation"
xtreg support4incumbent l1cpa3and4 l1cpa0 l1cpa1 diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate counciltax /* 
*/ y2004 y2005 y2006 y2007, fe cluster(lacode)

* Test H0: "Performance doesn't matter"
test l1cpa3and4 l1cpa0 l1cpa1

dis "Do the outlying CPA categories 'have the same effect'?"
test l1cpa3and4=l1cpa0=l1cpa1

*Page 1281: Footnote 6: "These results also hold in alternative specifications, where all but
* one of the CPA categories are represented by individual dummy
* variables. It is for clarity of exposition that we group both the two
* lowest and the two highest categories together in the two
* formulations of the threshold model."

* "reward formulation"
xtreg support4incumbent l1cpa1 l1cpa2 l1cpa3 l1cpa4 diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate counciltax /* 
*/ y2004 y2005 y2006 y2007, fe cluster(lacode)

* Test H0: "Performance doesn't matter"
test l1cpa1 l1cpa2 l1cpa3 l1cpa4

dis "Do the higher CPA categories 'bring the same reward'?"
test l1cpa2=l1cpa3=l1cpa4

* "extremes formulation"
xtreg support4incumbent l1cpa0 l1cpa1 l1cpa3 l1cpa4 diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate counciltax /* 
*/ y2004 y2005 y2006 y2007, fe cluster(lacode)

* Test H0: "Performance doesn't matter"
test l1cpa0 l1cpa1 l1cpa3 l1cpa4

dis "Do the outlying CPA categories 'have the same effect'?"
test l1cpa0=l1cpa1=l1cpa3=l1cpa4

* Page 1282: Footnote 8: "Second, we
* augmented them with additive and multiplicative terms testing
* whether the performance variables are moderated by the percentage
* of total incumbent seats held by the dominant party in
* the incumbent coalition, which takes on the value of 100% in
* case of a administration controlled by a single party. Only in one
* case could the null hypothesis of no interactions be rejected."

* Make moderator:
gen int seniorincpc = .
replace seniorincpc = 100 if support4incumbent ~= . & coalitionvote == .
sort lacode year
gen int seniorcon = .
replace seniorcon = 1 if lagcoal_con_involved == 1 & lagcoal_lab_involved == 1 /*
*/ & (L1.conseats > L1.labseats)
replace seniorcon = 1 if lagcoal_con_involved == 1 & lagcoal_ld_involved == 1 /*
*/ & (L1.conseats > L1.libseats)
replace seniorcon = 1 if lagcoal_con_involved == 1 & lagcoal_lab_involved == 1 /*
*/ & lagcoal_ld_involved == 1 & (L1.conseats > L1.labseats) & (L1.conseats > L1.libseats)
gen int seniorlab = .
replace seniorlab = 1 if lagcoal_con_involved == 1 & lagcoal_lab_involved == 1 /*
*/ & (L1.conseats < L1.labseats)
replace seniorlab = 1 if lagcoal_lab_involved == 1 & lagcoal_ld_involved == 1 /*
*/ & (L1.labseats > L1.libseats)
replace seniorlab = 1 if lagcoal_con_involved == 1 & lagcoal_lab_involved == 1 /*
*/ & lagcoal_ld_involved == 1 & (L1.conseats < L1.labseats) & (L1.labseats > L1.libseats)
gen int seniorld = .
replace seniorld = 1 if lagcoal_con_involved == 1 & lagcoal_ld_involved == 1 /*
*/ & (L1.conseats < L1.libseats)
replace seniorld = 1 if lagcoal_lab_involved == 1 & lagcoal_ld_involved == 1 /*
*/ & (L1.labseats < L1.libseats)
replace seniorld = 1 if lagcoal_con_involved == 1 & lagcoal_lab_involved == 1 /*
*/ & lagcoal_ld_involved == 1 & (L1.conseats < L1.libseats) & (L1.labseats < L1.libseats)
replace seniorincpc = 100 if support4incumbent ~= . & lagcoal_con_involved == 1
replace seniorincpc = 100 if support4incumbent ~= . & lagcoal_lab_involved == 1
replace seniorincpc = 100 if support4incumbent ~= . & lagcoal_ld_involved == 1
replace seniorincpc = 100*(L1.conseats/(L1.conseats + L1.labseats)) if /*
*/ lagcoal_con_involved == 1 & lagcoal_lab_involved == 1 & seniorcon == 1
replace seniorincpc = 100*(L1.conseats/(L1.conseats + L1.libseats)) if /*
*/ lagcoal_con_involved == 1 & lagcoal_ld_involved == 1 & seniorcon == 1
replace seniorincpc = 100*(L1.conseats/(L1.conseats + L1.labseats /*
*/ + L1.libseats)) if lagcoal_con_involved == 1 & lagcoal_lab_involved == 1 /*
*/ & lagcoal_ld_involved == 1 & seniorcon == 1
replace seniorincpc = 100*(L1.labseats/(L1.conseats + L1.labseats)) if /*
*/ lagcoal_con_involved == 1 & lagcoal_lab_involved == 1 & seniorlab == 1
replace seniorincpc = 100*(L1.labseats/(L1.labseats + L1.libseats)) if /*
*/ lagcoal_lab_involved == 1 & lagcoal_ld_involved == 1 & seniorlab == 1
replace seniorincpc = 100*(L1.labseats/(L1.conseats + L1.labseats /*
*/ + L1.libseats)) if lagcoal_con_involved == 1 & lagcoal_lab_involved == 1 /*
*/ & lagcoal_ld_involved == 1 & seniorlab == 1
replace seniorincpc = 100*(L1.libseats/(L1.conseats + L1.libseats)) if /*
*/ lagcoal_con_involved == 1 & lagcoal_ld_involved == 1 & seniorld == 1
replace seniorincpc = 100*(L1.libseats/(L1.labseats + L1.libseats)) if /*
*/ lagcoal_lab_involved == 1 & lagcoal_ld_involved == 1 & seniorld == 1
replace seniorincpc = 100*(L1.libseats/(L1.conseats + L1.labseats /*
*/ + L1.libseats)) if lagcoal_con_involved == 1 & lagcoal_lab_involved == 1 /*
*/ & lagcoal_ld_involved == 1 & seniorld == 1
compress
save, replace
sum seniorincpc, d
sum seniorincpc if seniorincpc < 100, d

* Make interaction terms:

* for (1.1) Proportionate response to performance model
gen seniorXl1sp_per = seniorincpc * l1sp_per

* for (1.2) Non-proportionate: performance decline relative to the past model
gen seniorXpos = seniorincpc * sp_per_pos1_3_sd
gen seniorXneg = seniorincpc * sp_per_neg1_3_sd

* for (2.1) Threshold model: Reward formulation
gen l1cpa2andbetter = .
replace l1cpa2andbetter = 0 if l1cpa0 == 1 | l1cpa1 == 1
replace l1cpa2andbetter = 1 if l1cpa2 == 1 | l1cpa3 == 1 | l1cpa4 == 1
gen seniorXl1cpa2plus = seniorincpc * l1cpa2andbetter

* for (2.2) Threshold model: Extremes formulation
gen seniorXl1cpa3and4 = seniorincpc * l1cpa3and4
gen seniorXl1cpa0and1 = seniorincpc * l1cpa0and1

* for (2.3) Positivity and negativity model
gen seniorXcpaimproved = seniorincpc * cpaimproved
gen seniorXcpanegchange = seniorincpc * cpanegchange

* for (3.1) Proportionate response to performance model
gen seniorX_3 = seniorincpc * _3

* Re-estimate models with interactions included:

* (1.1) Proportionate response to performance model
xtreg support4incumbent l1sp_per /*
*/ seniorincpc seniorXl1sp_per /*
*/ diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate counciltax /* 
*/ y2004 y2005 y2006 y2007, fe cluster(lacode)

* (1.1) Test seat share of the dominant party among incumbent coalition
test seniorincpc seniorXl1sp_per

* (1.1) Test interaction
test seniorXl1sp_per

* (1.2) Non-proportionate: performance decline relative to the past model
xtreg support4incumbent sp_per_pos1_3_sd sp_per_neg1_3_sd /*
*/ seniorincpc seniorXpos seniorXneg /*
*/ diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate counciltax /* 
*/ y2005 y2006 y2007, fe cluster(lacode)

* (1.2) Test seat share of the dominant party among incumbent coalition
test seniorincpc seniorXpos seniorXneg

* (1.2) Test interactions
test seniorXpos seniorXneg

* (2.1) Threshold model: Reward formulation
xtreg support4incumbent l1cpa2andbetter /*
*/ seniorincpc seniorXl1cpa2plus /*
*/ diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate counciltax /* 
*/ y2004 y2005 y2006 y2007, fe cluster(lacode)

* (2.1) Test seat share of the dominant party among incumbent coalition
test seniorincpc seniorXl1cpa2plus

* (2.1) Test interaction
test seniorXl1cpa2plus

* (2.1) Get coefficients, variances, and covariances:
matrix b=e(b)
matrix V=e(V)
forval i = 1(1)3 {
   scalar b`i'=b[1,`i']
   dis "Check b`i' is correct:"
   dis b`i'
   scalar varb`i'=V[`i',`i']
   forval j = 1(1)3 {
      scalar covb`i'b`j'=V[`i',`j']
   }
}

#delimit ;

*     ****************************************************************  *;
*       Generate a variable indicating the dominant party's share of    *;
*       the governing coalition, which mostly lies in [80,100]          *;
*     ****************************************************************  *;

generate MV = ((_n+79));
lab var MV "Dominant party's share of coalition (100 if 1-party control)";

replace  MV = . if _n > 21;

*     ****************************************************************  *;
*       Calculate the effect of a CPA of 2 stars or better              *;
*     ****************************************************************  *;

gen conb= b1 + b3*1*MV if _n < 22;

*     ****************************************************************  *;
*       Calculate the relevant standard errors 				      *;
*     ****************************************************************  *;

gen conse = sqrt(varb1 + varb3*(1^2)*(MV^2)
                 + 2*covb1b3*1*MV) if _n<22;

*     ****************************************************************  *;
*       Generate upper and lower bounds of the confidence interval.     *;
*       Specify the significance of the confidence interval (here: 90%).*;
*     ****************************************************************  *;

gen a=1.96*conse;
 
gen upper=conb+a;
 
gen lower=conb-a;

*     ****************************************************************  *;
*       Graph the marginal effect of the turnover rate.                 *;
*       Show the confidence interval.                                   *;
*     ****************************************************************  *;

graph twoway line conb   MV, clwidth(medium) clcolor(blue) clcolor(black)
        ||   line upper  MV, clpattern(dash) clwidth(thin) clcolor(black)
        ||   line lower  MV, clpattern(dash) clwidth(thin) clcolor(black)
        ||   ,   
             xlabel(80 85 90 95 100, labsize(2.5)) 
             ylabel(-2 -1 0 1 2 3 4 5 6 7,   labsize(2.5))
             yscale(noline)
             xscale(noline)
             legend(off)
             yline(0, lcolor(black))   
             scheme(s2mono) graphregion(fcolor(white));
             
*     ****************************************************************  *;
*                 Figure can be saved in a variety of formats.          *;
*     ****************************************************************  *; 

translate @Graph JOP-CoalitionsFigure.wmf, replace;     

drop MV conb conse a upper lower;

#delimit cr;

* (2.2) Threshold model: Extremes formulation
xtreg support4incumbent l1cpa3and4 l1cpa0and1 /*
*/ seniorincpc seniorXl1cpa3and4 seniorXl1cpa0and1 /*
*/ diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate counciltax /* 
*/ y2004 y2005 y2006 y2007, fe cluster(lacode)

* (2.2) Test seat share of the dominant party among incumbent coalition
test seniorincpc seniorXl1cpa3and4 seniorXl1cpa0and1

* (2.2) Test interactions
test seniorXl1cpa3and4 seniorXl1cpa0and1

* (2.3) Positivity and negativity model
xtreg support4incumbent cpaimproved cpanegchange /*
*/ seniorincpc seniorXcpaimproved seniorXcpanegchange /*
*/ diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate counciltax /* 
*/ y2005 y2006 y2007, fe cluster(lacode)

* (2.3) Test seat share of the dominant party among incumbent coalition
test seniorincpc seniorXcpaimproved seniorXcpanegchange

* (2.3) Test interactions
test seniorXcpaimproved seniorXcpanegchange

* (3.1) Proportionate response to performance model
xtreg f1thruf3supp4incumbent _3 /*
*/ seniorincpc seniorX_3 /*
*/ f1thruf3diff2maxpartieslast /*
*/ f1thruf3lagsupport4inc f1thruf3laglabourcontrol f1thruf3laglibdemcontrol /*
*/ f1thruf3wholecouncil f1thruf3q1claimrate f1thruf3counciltax /* 
*/ y2003 y2006, fe cluster(lacode)

* (3.1) Test seat share of the dominant party among incumbent coalition
test seniorincpc seniorX_3

* (3.1) Test interaction
test seniorX_3

* Page 1281: Main text: "We examined whether the performance effects were
* contingent on the tone of news coverage. We reestimated
* all specifications of the performance models as
* interactive models, with a net positive news stories score
* moderating the effect of the performance indicator
* on the vote share of the incumbent administration.7
* However, in no case could we reject the null hypothesis
* of no interaction."

* Make variable for media coverage (exactly as in James/John 2007)
gen netposstories = n_positive - n_negative
* Make interaction terms
gen netposXl1sp_per = l1sp_per * netposstories
gen netposXsp_per_pos = sp_per_pos1_3_sd * netposstories
gen netposXsp_per_neg = sp_per_neg1_3_sd * netposstories
gen netposXl1cpa2 = l1cpa2 * netposstories
gen netposXl1cpa3_4 = l1cpa3and4 * netposstories
gen netposXl1cpa2plus = l1cpa2andbetter * netposstories
gen netposXcpa_up = cpaimproved * netposstories
gen netposXcpa_down = cpanegchange * netposstories

* (1.1)
xtreg support4incumbent l1sp_per /*
*/ netposstories netposXl1sp_per /*
*/ diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate counciltax /* 
*/ y2004 y2005 y2006 y2007, fe cluster(lacode)

sum support4incumbent if e(sample) & L1.controlchange == 1
sum support4incumbent if e(sample) & L1.controlchange == 0 & L1.elec == 0 /*
*/ & L2.controlchange == 1
sum support4incumbent if e(sample) & L1.controlchange == 0 & L1.elec == 0 /*
*/ & L2.elec == 0 & L2.controlchange == 0 & L3.controlchange == 1

* Test H0: Media coverage doesn't matter
test netposstories netposXl1sp_per

* Test H0: no interaction
test netposXl1sp_per

* (1.2)
xtreg support4incumbent sp_per_pos1_3_sd sp_per_neg1_3_sd /*
*/ netposstories netposXsp_per_pos netposXsp_per_neg /*
*/ diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate counciltax /* 
*/ y2005 y2006 y2007, fe cluster(lacode)

* Test H0: Media coverage doesn't matter
test netposstories netposXsp_per_pos netposXsp_per_neg

* Test H0: no interaction
test netposXsp_per_pos netposXsp_per_neg

* (2.1)
xtreg support4incumbent l1cpa2 l1cpa3and4 /*
*/ netposstories netposXl1cpa2 netposXl1cpa3_4 /*
*/ diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate counciltax /* 
*/ y2004 y2005 y2006 y2007, fe cluster(lacode)

* Test H0: Media coverage doesn't matter
test netposstories netposXl1cpa2 netposXl1cpa3_4

* Test H0: no interaction
test netposXl1cpa2 netposXl1cpa3_4

* (2.3)
xtreg support4incumbent cpaimproved cpanegchange /*
*/ netposstories netposXcpa_up netposXcpa_down /*
*/ diff2maxpartieslast /*
*/ lagsupport4inc laglabourcontrol laglibdemcontrol /*
*/ wholecouncil q1claimrate counciltax /* 
*/ y2005 y2006 y2007, fe cluster(lacode)

* Test H0: Media coverage doesn't matter
test netposstories netposXcpa_up netposXcpa_down

* Test H0: no interaction
test netposXcpa_up netposXcpa_down

* Page 1281: Footnote 4: "As a robustness check, we tested whether this finding is 
* moderated by the percentage of citizen stating that they are
* satisfied with their local government�s service performance (the
* core explanatory variable of the model in Table 3). Yet there is no
* such interaction. This model only shows a relationship for the
* CPA, as reported in the threshold model in Table 2."

gen cpa2andbetter = .
replace cpa2andbetter = 0 if cpa < 2
replace cpa2andbetter = 1 if cpa > 1 & cpa ~= .

gen f1thruf3cpa2andbetter = .
replace f1thruf3cpa2andbetter = F1.cpa2andbetter if f1support4incumbent ~= .
replace f1thruf3cpa2andbetter = F2.cpa2andbetter if f1support4incumbent == . /*
*/ & f2support4incumbent ~= .
replace f1thruf3cpa2andbetter = F3.cpa2andbetter if f1support4incumbent == . /*
*/ & f2support4incumbent == . & f3support4incumbent ~= .

gen CPAX_3 = f1thruf3cpa2andbetter * _3

xtreg f1thruf3supp4incumbent _3 /*
*/ f1thruf3cpa2andbetter CPAX_3 /*
*/ f1thruf3diff2maxpartieslast /*
*/ f1thruf3lagsupport4inc f1thruf3laglabourcontrol f1thruf3laglibdemcontrol /*
*/ f1thruf3wholecouncil f1thruf3q1claimrate f1thruf3counciltax /* 
*/ y2003 y2006, fe cluster(lacode)

* Test H0: CPA doesn't matter
test f1thruf3cpa2andbetter CPAX_3

* Test H0: _3 doesn't matter
test _3 CPAX_3

* Test H0: no interaction
test CPAX_3

* Test H0: neither measure of performance matters
test _3 f1thruf3cpa2andbetter CPAX_3

clear
erase workfile.dta
log close
# delimit cr
exit

* You can view a record of all operations and results in the JOP2009.smcl file.
